/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.common.util;

import org.apache.commons.lang3.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yunfeng.li
 * @version $Id: v 0.1 2017年03月31日 17:47 yunfeng.li Exp $
 */
public class WxTemplateUtil {

    public static Map<String, String> parseContent(String content) {
        Map<String, String> preMap = new LinkedHashMap<>();
        if (StringUtils.isBlank(content)) {
            return preMap;
        }
        String pattern = "([\\u4e00-\\u9fa5]*)：?\\{\\{(\\w+)\\.DATA\\}\\}";
        Matcher matcher = Pattern.compile(pattern).matcher(content);
        while (matcher.find()) {
            String value = matcher.group(1);
            if (StringUtils.isNotBlank(value)) {
                value = value + "：";
            }
            String key = matcher.group(2);
            preMap.put(key, value);
        }
        return preMap;
    }
}
